package com.fanfanwang.ffw.app.asynctask;


import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.LinkedHashMap;


import com.fanfanwang.ffw.app.R;
import com.fanfanwang.ffw.app.bean.CityListBean;
import com.fanfanwang.ffw.app.bean.CitySecondBean;
import com.fanfanwang.ffw.app.bean.SucChksmsBean;
import com.fanfanwang.ffw.app.bean.SucGetCityListBean;
import com.fanfanwang.ffw.app.bean.SucGetUserInfoBean;
import com.fanfanwang.ffw.app.bean.SucGetparkingListBean;
import com.fanfanwang.ffw.app.bean.SucIsRegBean;
import com.fanfanwang.ffw.app.bean.SucLoginBean;
import com.fanfanwang.ffw.app.bean.SucRegBean;
import com.fanfanwang.ffw.app.bean.SucSaveFeedbackBean;
import com.fanfanwang.ffw.app.bean.SucSetPasswordBean;
import com.fanfanwang.ffw.app.bean.SucUpdateMobileBean;
import com.fanfanwang.ffw.app.bean.SucUpdateUserinfoBean;
import com.fanfanwang.ffw.app.common.Md5Util;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.fragment.MainTingcheFragment;
import com.fanfanwang.ffw.app.net.HttpRequest.HttpRequestException;
import com.fanfanwang.ffw.app.net.IssAsyncTask;
import com.fanfanwang.ffw.app.net.IssNetLib;
import com.fanfanwang.ffw.app.net.WebServiceHelper;

import android.app.Activity;
import android.os.AsyncTask;
import android.text.TextUtils;


public class GetCityListAsyncTask extends AsyncTask<String, String, SucGetCityListBean> {
	private Activity mActivity;
	private String city_id;
	public GetCityListAsyncTask(Activity activity,String city_id) {
		super();
		//		super(activity,true,false);
		mActivity = activity;
		this.city_id = city_id;
	}

	@Override
	protected SucGetCityListBean doInBackground(String... params) {
		// TODO 	addAuctionPrice($apiusername,$apipassword,$userid,$pid,$price)
		SucGetCityListBean bean = null;
		LinkedHashMap<String, Object> paramsMap = new LinkedHashMap<String, Object>();
		paramsMap.put("apiusername", "parking");
		paramsMap.put("apipassword", Md5Util.getMD5To32("parking"));
		paramsMap.put("city_id", city_id);
		try {
			bean = IssNetLib.getInstance(mActivity).getCityList(WebServiceHelper._GETCITYLIST, paramsMap);

			//TODO 自己定义数据
			/*bean =new SucGetCityListBean();
			ArrayList<CityListBean> list=new ArrayList<CityListBean>();
			CityListBean cityListBean=new CityListBean();
			cityListBean.id="23";
			cityListBean.title="%E9%95%BF%E5%AE%89%E5%8C%BA";
			CitySecondBean citySecondBean=new CitySecondBean();
			citySecondBean.id="428";
			citySecondBean.title="%E4%B8%87%E8%BE%BE%E5%B9%BF%E5%9C%BA";
			ArrayList<CitySecondBean> secondList=new ArrayList<CitySecondBean>();
			secondList.add(citySecondBean);
			cityListBean.data=secondList;
			list.add(cityListBean);
			bean.status=1;
			bean.data=list;*/
		} catch (HttpRequestException e) {
			e.printStackTrace();
			//exception = getResources().getString(R.string.e_net_error);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//exception = getResources().getString(R.string.e_json);
		}
		return bean;
	}

	@Override
	protected void onPostExecute(SucGetCityListBean result) {
		super.onPostExecute(result);
		/*	if (exception != null) {
			ToastAlone.showToast(mActivity, exception);
			return;
		}*/
		if (result != null) {
			if (result.status == 1) {

				if(result.data != null){
					MainTingcheFragment.iGetCityList.getCityList(result.data);
				}
			}else if(result.status == 0){
				if(result.msg != null && !TextUtils.isEmpty(result.msg)){
					try {
						ToastAlone.showToast(mActivity, URLDecoder.decode(result.msg,"utf-8"), ToastAlone.LENGTH_SHORT);
					} catch (UnsupportedEncodingException e) {
						e.printStackTrace();
					}
				}else {
					ToastAlone.showToast(mActivity, mActivity.getResources().getString(R.string.e_net_error), ToastAlone.LENGTH_SHORT);
				}
			}
		}
	}
}
